package dp.onClass.class1.exer01;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int rows = sc.nextInt();
        List<List<Integer>> list = new ArrayList<>();
        for (int i = 1; i <= rows; i++) {
            List<Integer> curList = new ArrayList<>();
            for (int j = 1; j <= i; j++) {
                curList.add(sc.nextInt());
            }
            list.add(curList);
        }
        int[][] dp = new int[rows][rows];
        dp[0][0] = list.get(0).get(0);
        for (int i = 1; i < rows; i++) {
            dp[i][0] = dp[i - 1][0] + list.get(i).get(0);
        }
        for (int i = 1; i < rows; i++) {
            for (int j = 1; j < i; j++) {
                dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - 1]) + list.get(i).get(j);
            }
            dp[i][i] = dp[i - 1][i - 1] + list.get(i).get(i);
        }
        int lowestMax = -1;
        for (int i = 0; i < rows; i++) {
            lowestMax = Math.max(lowestMax, dp[rows - 1][i]);
        }
        System.out.println(lowestMax);

    }
}
